/*
Copyright (c) 2010 Vadim Seregin
Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
*/

#ifndef WORDLIST_H
#define WORDLIST_H

#include "wx/wxsqlite3.h"
#include "../../res/worddialog.h" // Base class: WordDialog
#include "baselist.h"

class WordList : public WordDialog, public BaseList
{

public:
	WordList( wxString& dict,wxSQLite3Database *pDictDb, wxSQLite3Database *pCardDb, wxString& soundFileDir );
	~WordList();
	
	// load list
	void Load();
	
	// get number of words
	long GetWordsNum(){ return m_iWordNum; }
	
	bool GetWordInfo( wxString& id, wxString& word, wxString& tran );

	wxString GetWordId(){ return m_sWordId; }
	wxString GetSelectedWord(){ return m_sWord; }
	wxString GetTranslation(){ return m_sTran; }
	
protected:
	// get word
	wxString GetWord(){ return m_textCtrlWord->GetLineText(0); }
	
	// get translation
	wxString GetTran()
	{ 
		wxString str = m_textCtrlTran->GetLineText(0);
		for( int i = 1; i < m_textCtrlTran->GetNumberOfLines(); i++ )
			str += wxT("\n") + m_textCtrlTran->GetLineText(i);
			
		return str; 
	}
	
	// get sound file
	wxString GetFile(){ return m_textCtrlFile->GetLineText(0); }

	// set word
	void SetWord( wxString& str ){ m_textCtrlWord->SetValue( str ); }
	
	// set translation
	void SetTran( wxString& str ){ m_textCtrlTran->SetValue( str ); }
	
	// set sound file
	void SetFile( wxString& str ){ m_textCtrlFile->SetValue( str ); }
	
	// fill list with words and return the number of words
	long FillWordList( bool bClear = false );
	
	// clear info
	void ClearInfo();

	// set word info
	void SetInfo();
	
	// update item in the list
	void UpdateItem();
	
	// ======================== events ================================
	// cancel button
	virtual void OnOkClick( wxCommandEvent& event );
	
	// cancel button
	virtual void OnCancelClick( wxCommandEvent& event );
	
	// delete dict creation
	virtual void OnDeleteClick( wxCommandEvent& event );
	
	// if list item is selected
	virtual void OnWordSelected( wxListEvent& event );
	
	// if list item is deselected
	virtual void OnWordDeselected( wxListEvent& event );
	
	// insert word to the dict
	virtual void OnInputClick( wxCommandEvent& event );
	
	// select file
	virtual void OnFileClick( wxCommandEvent& event );
	
	// play file
	virtual void OnPlayClick( wxCommandEvent& event );
	
	// left double click
	virtual void OnLeftDClick( wxMouseEvent& event );
	
	// key down
	virtual void OnKeyDown( wxKeyEvent& event );

	// enter window
	virtual void OnEnterWindow( wxMouseEvent& event );

protected:
	enum eWord
	{
		eWord_Id = 0,
		eWord_Word,
		eWord_Tran,	
		eWord_Cols
	};
	
	wxSQLite3Database *m_pDictDb;  // dict database
	wxSQLite3Database *m_pCardDb;  // card database
	wxString m_sWordId;            // word id
	wxString m_sWord;              // word
	wxString m_sTran;              // translation
	wxString m_sFile;              // sound file
	wxString m_sDictName;          // dict name table in db
	long     m_iWordNum;           // number of words in the dict

};

#endif // WORDLIST_H
